/*
 * Copyright (c) 2011 Yoyo Systems. All rights reserved.
 *
 * $Id$
 */
package com.ebo.storage.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;


public class RedisShardInfo {

	private int timeout;
    private String shardName;
    private String masterHost;
    private int masterPort;

    public RedisShardInfo(String shardName, String masterHost) {
        this(shardName, masterHost, Protocol.DEFAULT_PORT);
    }

    public RedisShardInfo(String shardName, String masterHost, int masterPort) {
        this(shardName, masterHost, masterPort, 15000);
    }

    public RedisShardInfo(String shardName, String masterHost, int masterPort, int timeout) {
        this.shardName = shardName;
        this.masterHost = masterHost;
        this.masterPort = masterPort;
        this.timeout = timeout;
    }
    
    public String getMasterHost() {
        return masterHost;
    }

    public int getMasterPort() {
        return masterPort;
    }

    public String getShardName() {
        return shardName;
    }

    public int getTimeout() {
        return timeout;
    }

    public Jedis createResource() {
    	Jedis jedis = new Jedis(masterHost, masterPort, timeout);
    	return jedis;
    }
    
    public String toString() {
        StringBuilder sb = new StringBuilder("<Redis master='");
        sb.append(masterHost);
        sb.append(":");
        sb.append(masterPort);
        sb.append("'/>");
        return sb.toString();
    }
}
